package com.probiz.estore.common.model.catalog;

import com.probiz.estore.common.model.catalog.base.ContentCategoryTbl;
import org.apache.commons.lang.StringUtils;

/**
 * Model class for ContentCategory. Add not database mapped fileds in this class.
 * 内容目录
 * 
 * 目前已使用的关键目录编码
 * 帮助中心-helpCenter
 * 使用协议-agreement
 * 隐私声明-privacy
 */
public class ContentCategory extends ContentCategoryTbl {
    public final static Short STATUS_ACTIVE = (short) 1;
    public final static Short STATUS_INACTIVE = (short) 0;
    public final static Integer SORTORDER_DEFAULT_VALUE = new Integer("9999");

    public final static Short TYPE_ARTICLE = (short) 1;//文章栏目
    public final static Short TYPE_PAGE = (short) 2;//单独页面
    public final static Short TYPE_LINK = (short) 3; //链接地址

    /**
     * Default Empty Constructor for class ContentCategory
     */
    public ContentCategory() {
        super();
    }

    /**
     * Default Key Fields Constructor for class ContentCategory
     * @param in_categoryId 目录id
     */
    public ContentCategory(Integer in_categoryId) {
        super(in_categoryId);
    }

    /**
     * 定义实体的业务名取值
     * @return 实体业务名
     */
    public String getContentCategoryName() {
        if (categoryId == null)
            return "";
        else
            return this.categoryName;
    }

	/**
     * 获取完整的目录路径名 例：主页>最新消息>工业信息>起重机
	 * @return 完整的目录路径名 
	 */
	public String getFullCategoryPathName() {
		if(StringUtils.isNotBlank(getParentFullCategoryPathName())){
			return getParentFullCategoryPathName()+">"+getCategoryName();
		}else{
			return getCategoryName();
		}
	}

	/**
     * 简单的目录路径名(不包含根) 例：最新消息>工业信息>起重机
	 * @return 获取简单的目录路径名(不包含根) 
	 */
	public String getSimpleCategoryPathName(){
		StringBuffer categoryPathNameBuffer=new StringBuffer(100);
		ContentCategory parentCategory=this.getParent();
		while (parentCategory!=null && parentCategory.getCategoryId() !=1) {
			categoryPathNameBuffer.insert(0, ">");
			categoryPathNameBuffer.insert(0, parentCategory.getCategoryName());
			parentCategory=parentCategory.getParent();
		}
		String categoryPathName = categoryPathNameBuffer.toString();
		if(!StringUtils.isEmpty(categoryPathName))categoryPathName = categoryPathName.substring(0,categoryPathName.length()-1);
		if(StringUtils.isBlank(categoryPathName)) {
			return getCategoryName();
		}else{
			return categoryPathName+">"+getCategoryName();
		}
	}
	/**
     * 父目录完整的目录路径名 例：主页>最新消息>工业信息
	 * @return 获取父目录完整的目录路径名 
	 */
	public String getParentFullCategoryPathName(){
		StringBuffer categoryPathNameBuffer=new StringBuffer(100);
		ContentCategory parentCategory=this.getParent();
		while (parentCategory!=null) {
			categoryPathNameBuffer.insert(0, ">");
			categoryPathNameBuffer.insert(0, parentCategory.getCategoryName());
			parentCategory=parentCategory.getParent();
		}
		String categoryPathName = categoryPathNameBuffer.toString();
		if(!StringUtils.isEmpty(categoryPathName))categoryPathName = categoryPathName.substring(0,categoryPathName.length()-1);
		return categoryPathName;
	}

}
